<%--
  Created by IntelliJ IDEA.
  User: 赵坤
  Date: 2020/7/24
  Time: 15：20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>会员充值信息管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${pageContext.request.contextPath}/back/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">会员ID</label>
          <div class="layui-input-block">
            <input type="text" name="vipId" placeholder="请输入" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button class="layui-btn layuiadmin-btn-forum-list" lay-submit lay-filter="search">
            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
          </button>
        </div>
      </div>
    </div>

    <div class="layui-card-body">
      <script id="vip_tool_title" type="text/html">
        <div style="padding-bottom: 10px;">
          <button type="button" id="add" class="layui-btn"><i class="layui-icon"></i>添加会员充值信息</button>
        </div>
      </script>

      <table id="LAY-app-forum-list" lay-filter="LAY-app-forum-list"></table>


      <script type="text/html" id="table-forum-list">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
      </script>
    </div>
  </div>
</div>

<script src="${pageContext.request.contextPath}/back/layuiadmin/layui/layui.js"></script>
<script>
  layui.config({
    base: '${pageContext.request.contextPath}/back/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'forum', 'table'], function(){
    var $ = layui.$
            ,form = layui.form
            ,table = layui.table;
    var cols =[[
      {field:'vipOrdersId', title:'会员卡订单号', unresize: true, sort: true,fixed: 'left'}
      ,{field:'accountId', title:'用户账号', unresize: true, sort: true,fixed: 'left'}
      ,{field:'vipOrdersPrice', title:'会员充值金额',unresize: true,sort: true,fixed: 'left'}
      ,{field:'vipStartTime', title:'会员充值时间',unresize: true,sort: true,fixed: 'left'}
      ,{field:'vipEndTime', title:'会员到期时间',unresize: true, sort: true,fixed: 'left'}
      ,{field:'vipTypeId', title:'会员类型',unresize: true,sort: true,templet:function(data) {
          let vipTypeId = data.vipTypeId;
          if (vipTypeId == "M") {
            return "月卡";
          } else if (vipTypeId == "S") {
            return "季卡";
          } else if (vipTypeId == "Y") {
            return "年卡";
          }
        }}
    ]];

    // 搜索
    table.render({
      elem: '#LAY-app-forum-list'
      ,url: '${pageContext.request.contextPath}/back/vipOrdersInfo' //数据接口
      ,toolbar: "#vip_tool_title"
      ,page: true //开启分页
      ,cols: cols
      ,parseData:function(res){
        return {
          "code": 0, //解析接口状态
          "msg": "搜索成功", //解析提示文本
          "count": res.total, //解析数据长度
          "data": res.list, //解析数据列表
        };
      }
    });


    form.on('submit(search)',function(data){
      var field = data.field;
      /*layer.msg("正在搜索");*/
      table.render({
        elem: '#LAY-app-forum-list'
        ,url: "${pageContext.request.contextPath}/back/vipOrdersInfo"//数据接口
        ,where: field
        ,toolbar: "#vip_tool_title"
        ,page: true //开启分页
        ,cols: cols
        ,parseData:function(res){
          return {
            "code": 0, //解析接口状态
            "msg": "提交搜索", //解析提示文本
            "count": res.total, //解析数据长度
            "data": res.list, //解析数据列表
          };
        }
      });
    });

    // 添加
    $("#add").click(function(){
      layer.open({
        type: 1
        ,title:"添加会员信息"
        ,content:$("#add_vip_info")
        ,area: ['500px', '220px']
        ,btn: ['确定', '取消']
      });
    });
    form.on("submit(add_vip)",function(data){
      let field = data.field;
      $.ajax({
        type:"post"
        ,url:"${pageContext.request.contextPath}/back/vipOrdersInfo"
        ,data:field
        ,success:function(result){
          if(result){
            layer.confirm("添加成功",function(){
              parent.location.reload();
            },function () {
              parent.location.reload();
            });
          }else{
            layer.msg("添加失败");
          }
        }
        ,error:function(){
          layer.msg("ajax错误");
        }
      });
    });

  });



</script>

<!-- 添加会员用户信息表 -->
<div class="layui-form" id="add_vip_info" style="display:none"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
  <div class="layui-form-item">
    <label class="layui-form-label">用户账号</label>
    <div class="layui-input-block">
      <input type="text" name="accountId" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">充值类型</label>
    <div class="layui-input-block">
      <input type="text" name="vipTypeId" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">充值价格</label>
    <div class="layui-input-block">
      <input type="text" name="vipOrdersPrice" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="add_vip">确认添加</button>
    </div>
  </div>
</div>

</body>
</html>